using UnityEngine;

public class RectTransformAspectScaler : MonoBehaviour
{
	public float aspectFrom = 1.333333f;

	public float aspectTo = 1.777777f;

	public float scaleFrom = 1f;

	public float scaleTo = 1.12f;

	public bool doScale = true;

	public bool destroyAfter = true;

	private void Update()
	{
		if (doScale)
		{
			doScale = false;
			UpdateScaleForAspectRatio();
			if (destroyAfter)
			{
				Object.Destroy(this);
			}
		}
	}

	public void UpdateScaleForAspectRatio()
	{
		base.transform.localScale = Vector3.one * GetScaleForAspectRatio(scaleFrom, scaleTo, aspectFrom, aspectTo);
	}

	public static float GetScaleForAspectRatio(float scaleFrom_ = 1f, float scaleTo_ = 1.12f, float aspectFrom_ = 1.333333f, float aspectTo_ = 1.777777f)
	{
		float num = (float)Screen.width / (float)Screen.height;
		return scaleFrom_ + (scaleTo_ - scaleFrom_) * ((num - aspectFrom_) / (aspectTo_ - aspectFrom_));
	}
}
